/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sengoku;

import javax.swing.JOptionPane;

/**
 *
 * @author Ronald
 */
public class Board {

    int side = 6;
    Piece[][] spaces = new Piece[6][6];

    public Board() {
        for (int row = 00; row < side; row++) {
            for (int column = 0; column < side; column++) {
                spaces[row][column] = new Piece();
            }
        }
    }

    public void MakePieces() {
        Piece upperAlpha1 = new Piece(" [A] ", " [A] ", 4, 2, true, true, true);
        Piece upperAlpha2 = new Piece(" [A] ", " [A] ", 4, 3, true, true, true);
        Piece upperBravo1 = new Piece(" [B] ", " [B] ", 4, 1, true, true, false);
        Piece upperBravo2 = new Piece(" [B] ", " [B] ", 4, 4, true, true, false);
        Piece lowerAlpha1 = new Piece(" [a] ", " [a] ", 1, 2, false, true, true);
        Piece lowerAlpha2 = new Piece(" [a] ", " [a] ", 1, 3, false, true, true);
        Piece lowerBravo1 = new Piece(" [b] ", " [b] ", 1, 1, false, true, false);
        Piece lowerBravo2 = new Piece(" [b] ", " [b] ", 1, 4, false, true, false);
        spaces[4][2] = upperAlpha1;
        spaces[4][3] = upperAlpha2;
        spaces[4][1] = upperBravo1;
        spaces[4][4] = upperBravo2;
        spaces[1][2] = lowerAlpha1;
        spaces[1][3] = lowerAlpha2;
        spaces[1][1] = lowerBravo1;
        spaces[1][4] = lowerBravo2;
    }

    public void MakeBoard() {
        String space = "    ";
        for (int index = 0; index < side; index++) {
            space += index + "    ";
        }
        space += "\n";
        for (int row = 0; row < side; row++) {
            space += row;
            for (int column = 0; column < side; column++) {
                space += spaces[row][column].name;
            }
            space += "\n";
        }
        System.out.println(space);
    }

    public void Play() {
        while (1 > 0) {
            String r = JOptionPane.showInputDialog("What row? ");
            int row = Integer.parseInt(r);
            String c = JOptionPane.showInputDialog("What column? ");
            int column = Integer.parseInt(c);
            if (spaces[row][column].isUpperCase) {
                if (spaces[row][column].isAlpha) {
                    if (spaces[row][column].isOccupied) {
                        spaces[row][column].blankPiece();
                        String m = JOptionPane.showInputDialog("To move this piece enter either up, down, left, or right: ");
                        String move = m;
                        if (move.equalsIgnoreCase("up")) {
                            spaces[row + 1][column].getStateA();
                        } else if (move.equalsIgnoreCase("down")) {
                            spaces[row - 1][column].getStateA();
                        } else if (move.equalsIgnoreCase("left")) {
                            spaces[row][column - 1].getStateA();
                        } else if (move.equalsIgnoreCase("right")) {
                            spaces[row][column + 1].getStateA();
                        }
                        MakeBoard();
                    } else {
                        System.out.println("ERROR: Select an occupied piece on the board");
                    }
                } else {
                    // stuff for beta pieces
                    if (spaces[row][column].isOccupied) {
                        spaces[row][column].blankPiece();
                        String m = JOptionPane.showInputDialog("To move this piece enter either forright, forleft, backleft, or backright: ");
                        String move = m;
                        if (move.equalsIgnoreCase("forright")) {
                            spaces[row + 1][column + 1].getStateB();
                        } else if (move.equalsIgnoreCase("forleft")) {
                            spaces[row + 1][column - 1].getStateB();
                        } else if (move.equalsIgnoreCase("backleft")) {
                            spaces[row - 1][column - 1].getStateB();
                        } else if (move.equalsIgnoreCase("backright")) {
                            spaces[row - 1][column + 1].getStateB();
                        }
                        MakeBoard();
                    } else {
                        System.out.println("ERROR: Select an occupied piece on the board");
                    }
                }
            } else {
                if (spaces[row][column].isAlpha) {
                    if (spaces[row][column].isOccupied) {
                        spaces[row][column].blankPiece();
                        String m = JOptionPane.showInputDialog("To move this piece enter either up, down, left, or right: ");
                        String move = m;
                        if (move.equalsIgnoreCase("up")) {
                            spaces[row + 1][column].getStateLA();
                        } else if (move.equalsIgnoreCase("down")) {
                            spaces[row - 1][column].getStateLA();
                        } else if (move.equalsIgnoreCase("left")) {
                            spaces[row][column - 1].getStateLA();
                        } else if (move.equalsIgnoreCase("right")) {
                            spaces[row][column + 1].getStateLA();
                        }
                        MakeBoard();
                    } else {
                        System.out.println("ERROR: Select an occupied piece on the board");
                    }
                } else {
                    // stuff for beta pieces
                    if (spaces[row][column].isOccupied) {
                        spaces[row][column].blankPiece();
                        String m = JOptionPane.showInputDialog("To move this piece enter either forright, forleft, backleft, or backright: ");
                        String move = m;
                        if (move.equalsIgnoreCase("forright")) {
                            spaces[row + 1][column + 1].getStateLB();
                        } else if (move.equalsIgnoreCase("forleft")) {
                            spaces[row + 1][column - 1].getStateLB();
                        } else if (move.equalsIgnoreCase("backleft")) {
                            spaces[row - 1][column - 1].getStateLB();
                        } else if (move.equalsIgnoreCase("backright")) {
                            spaces[row - 1][column + 1].getStateLB();
                        }
                        MakeBoard();
                    } else {
                        System.out.println("ERROR: Select an occupied piece on the board");
                    }
                }
            }
        }
    }
}
